package yartiss.gui.graphics.rendrerers;

import javax.swing.JInternalFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;

import yartiss.gui.graphics.IChartRenderer;
import yartiss.service.model.Metric;

public class LineChartRenderer implements IChartRenderer<Metric> {

	@Override
	public JInternalFrame render(Metric model , boolean isDebug) {
		JInternalFrame frame = new JInternalFrame(model.getName(),true,true,true,true);
		JFreeChart lineChart = ChartFactory.createLineChart("", "Scenarios", model.getName(), model.getData(),PlotOrientation.VERTICAL, true, true, false);
		
		CategoryPlot plot = (CategoryPlot) lineChart.getPlot();
		CategoryAxis domainAxis = plot.getDomainAxis();
		domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
		
		ChartPanel panel = new ChartPanel(lineChart);
		frame.setContentPane(panel);
		frame.setVisible(true);
		return frame;
	}

}
